package com.secxiot.consumer.user.feign;

import com.secxiot.provider.DeptApi;
import com.secxiot.provider.communication.dto.CommunicationCreateDto;
import com.secxiot.provider.communication.dto.CommunicationDetailCreateDto;
import com.secxiot.provider.communication.vo.*;
import com.secxiot.provider.system.dto.*;
import com.secxiot.provider.system.entity.AppPunchCard;
import com.secxiot.provider.system.entity.AppRecommend;
import com.secxiot.provider.system.entity.AppSchedulRecord;
import com.secxiot.provider.system.entity.FileLog;
import com.secxiot.provider.system.vo.*;
import com.secxiot.provider.task.vo.SosDeptFacilityVo;
import com.secxiot.provider.task.vo.TaskStatusVo;
import com.secxiot.provider.user.dto.BindDto;
import com.secxiot.provider.user.dto.DeptDto;
import com.secxiot.provider.user.dto.UserDeptDto;
import com.secxiot.provider.user.dto.UserDto;
import com.secxiot.provider.user.entity.SysExchangeRecord;
import com.secxiot.provider.user.entity.SysExchangeRules;
import com.secxiot.provider.user.entity.UserAccount;
import com.secxiot.provider.user.entity.UserDo;
import com.secxiot.provider.user.vo.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@FeignClient(value = "remind-provider", path = "/provider")
@Component
public interface UserClient extends DeptApi {

    static String USER_PREFIX = "/users/";

    static String DEPT_PREFIX = "/depts/";

    static String SYS_PREFIX = "/system/";

    static String COMMUNICATIONS_PREFIX = "/communications";

    static String INTEGRAL_PREFIX = "/integral";

    @GetMapping(value = "/users/{userId}")
    UserDo getUser(@PathVariable("userId") Long userId);

    /**
     * 获取用户信息
     *
     * @param mobile     手机号码
     * @param clientType 终端类型
     * @return 用户信息
     */
    @GetMapping("/users")
    UserDo getUserByPhone(@RequestParam(value = "mobile", required = true) String mobile,
                          @RequestParam(value = "clientType", required = true) String clientType);

    @GetMapping("/users/wxOpenid")
    UserDo getUserByWxOpenid(@RequestParam("wxOpenid") String wxOpenid);

    @PostMapping("/users")
    UserDo registry(@RequestBody UserDto userDto);

    @PostMapping("/users/narcoticRegistry")
    UserDo narcoticRegistry(@RequestBody UserDto userDto);

    @PostMapping("/users/sosRegistry")
    UserDo sosRegistry(@RequestBody UserDto userDto);

    @PutMapping("/users")
    UserDo update(@RequestBody UserDto userDto);

    @PostMapping("/users/contact")
    public UserEmergencyContactVo addContact(@RequestParam(value = "userId", required = true) Long userId,
                                             @RequestParam(value = "relation", required = true) String relation,
                                             @RequestParam(value = "name", required = false) String name,
                                             @RequestParam(value = "mobile", required = true) String mobile);

    @GetMapping("/users/contact")
    UserEmergencyContactVo getContact(@RequestParam(value = "userId", required = true) Long userId);

    @GetMapping("/users/list")
    List<UserSimpleVo> getUserSimpleList(@RequestParam(value = "userId") Long userId,
                                         @RequestParam(value = "userType") List<String> userType, @RequestParam(value = "deptId") Long deptId,
                                         @RequestParam(value = "directFlag", required = false) Integer directFlag,
                                         @RequestParam(value = "taskType", required = false) String taskType);

    @GetMapping("/users/patientlist")
    List<PatientVo> getPatientList(@RequestParam(value = "deptId", required = true) Long deptId);

    @GetMapping("/users/sosReceiverList")
    List<UserSimpleVo> listHospitalSOSDoctor(@RequestParam(value = "hospitalId", required = true) Long hospitalId,
                                             @RequestParam(value = "deptId", required = false) Long deptId,
                                             @RequestParam(value = "taskType", required = true) String taskType);

    @GetMapping(SYS_PREFIX + "/dataDict")
    List<DataDictVo> listDataDict(@RequestParam(value = "parentCode", required = false) String parentCode);

    @PostMapping(SYS_PREFIX + "/filelog")
    public Long saveFileLog(@RequestBody FileLog fileLog);

    @GetMapping(SYS_PREFIX + "/filelog")
    public FileLogDto getFileUri(@RequestParam("logId") Long logId);

    @GetMapping(SYS_PREFIX + "/filelog/fileLogByCode")
    List<FileLogVo> selectFileByCode(@RequestParam(value = "code", required = false) String code);

    @PostMapping(SYS_PREFIX + "/filelog/use")
    Long useFileLogs(@RequestParam("logIds") List<Long> logIds);

    @GetMapping(SYS_PREFIX + "/app/version")
    AppVersionDto getAppVersion(@RequestParam String platform, @RequestParam String clientType);

    @GetMapping(SYS_PREFIX + "/app/banner")
    List<AppBannerDto> getAppBanner(@RequestParam(value = "userId", required = true) Long userId,
                                    @RequestParam(value = "hospitalId", required = false) Long hospitalId);

    @GetMapping(SYS_PREFIX + "/app/news")
    List<AppNewsDto> getAppNews(@RequestParam(value = "userId", required = true) Long userId,
                                @RequestParam(value = "hospitalId", required = false) Long hospitalId);

    @PostMapping("/users/bind")
    Integer bindUserRel(@RequestBody BindDto bindDto);

    @GetMapping("/depts/user")
    @Override
    public DeptDto getDeptByUserId(@RequestParam("userId") Long userId);

    @GetMapping("/depts/{deptId}")
    @Override
    public DeptDto getDeptByDeptId(@PathVariable("deptId") Long deptId);

    @GetMapping("/depts/{deptId}/subdept")
    @Override
    public List<DeptDto> listSubdeptByDeptId(@PathVariable("deptId") Long deptId);

    @GetMapping("/depts/hospitals")
    @Override
    List<HospitalVo> listHospitalsByUser(@RequestParam("userId") Long userId,
                                         @RequestParam("longitude") BigDecimal longitude,
                                         @RequestParam("latitude") BigDecimal latitude,
                                         @RequestParam("wxAppId") String wxAppId);

    @GetMapping("/depts/hospital/nearest")
    @Override
    HospitalVo getNearestHospital(@RequestParam("longitude") BigDecimal longitude,
                                  @RequestParam("latitude") BigDecimal latitude,
                                  @RequestParam("hospitalId") Long hospitalId);

    @GetMapping("/depts/hospital/detail/{id}")
    @Override
    HospitalVo getHospitalById(@RequestParam("id") Long id);

    @GetMapping("/depts/hospital/detailByDeptId/{deptId}")
    @Override
    HospitalVo getHospitalByDeptId(@RequestParam("deptId") Long deptId);

    /**
     * 获取医院详情
     *
     * @param longitude 经度
     * @param latitude  维度
     * @param deptId    部门Id
     * @return
     */
    @GetMapping("/depts/hospital/getHospitalDistance/detail")
    @Override
    HospitalVo getHospitalDistanceByDeptId(@RequestParam("longitude") BigDecimal longitude,
                                           @RequestParam("latitude") BigDecimal latitude,
                                           @RequestParam("deptId") Long deptId);


    @GetMapping("/depts/hospital/list")
    @Override
    List<HospitalVo> selectHospital();

    @GetMapping("/depts/sosFacility")
    @Override
    List<SosDeptFacilityVo> sosFacility(@RequestParam("deptId") Long deptId,
                                        @RequestParam("hospitalId") Long hospitalId);

    @GetMapping("/depts/subManagers")
    @Override
    List<UserSimpleVo> listSubManagers(@RequestParam("deptId") Long deptId);

    @GetMapping("/depts/suppers")
    @Override
    List<UserDeptDto> listSupperDeptByUserId(@RequestParam("userId") Long userId);

    @Override
    @GetMapping(DEPT_PREFIX + "/toLeaf")
    List<DeptDto> listToLeafByDeptId(@RequestParam("deptId") Long deptId);

    @GetMapping(COMMUNICATIONS_PREFIX + "/patientList")
    List<CommunicatePatientVo> getPatientList(@RequestParam(value = "userId", required = true) Long userId,
                                              @RequestParam(value = "userType", required = false) String userType,
                                              @RequestParam(value = "patientName", required = false) String patientName,
                                              @RequestParam(value = "pageNo", required = true) Long pageNo,
                                              @RequestParam(value = "pageSize", required = true) Long pageSize);

    @GetMapping(COMMUNICATIONS_PREFIX + "/doctorList")
    List<CommunicateDoctorVo> getDoctorList(@RequestParam(value = "userId") Long userId,
                                            @RequestParam(value = "doctorName", required = false) String doctorName,
                                            @RequestParam(value = "pageNo", required = true) Long pageNo,
                                            @RequestParam(value = "pageSize", required = true) Long pageSize);

    @PostMapping(COMMUNICATIONS_PREFIX + "/updatePatientExtro")
    Boolean updatePatientExtro(@RequestParam(value = "patientId", required = true) Long patientId,
                               @RequestParam(value = "memo", required = false) String memo,
                               @RequestParam(value = "beds", required = false) String beds);

    @PostMapping(COMMUNICATIONS_PREFIX + "/updateDoctorExtro")
    public Boolean updateDoctorExtro(@RequestParam(value = "doctorId", required = true) Long doctorId,
                                     @RequestParam(value = "memo", required = true) String memo);

    @GetMapping(COMMUNICATIONS_PREFIX + "/communicationlist")
    public List<CommunicationVo> getCommunicationlist(@RequestParam(value = "userId", required = true) Long userId,
                                                      @RequestParam(value = "userType", required = true) String userType,
                                                      @RequestParam(value = "doctorId", required = true) Long doctorId,
                                                      @RequestParam(value = "patientId", required = true) Long patientId,
                                                      @RequestParam(value = "title", required = false) String title,
                                                      @RequestParam(value = "pageNo", required = true) Long pageNo,
                                                      @RequestParam(value = "pageSize", required = true) Long pageSize);

    @GetMapping(COMMUNICATIONS_PREFIX + "/communicationDetaillist")
    public List<CommunicationDetailVo> getCommunicationDetaillist(
            @RequestParam(value = "readUserId", required = true) Long readUserId,
            @RequestParam(value = "communicationId", required = true) Long communicationId,
            @RequestParam(value = "pageNo", required = true) Long pageNo,
            @RequestParam(value = "pageSize", required = true) Long pageSize);

    @PostMapping(COMMUNICATIONS_PREFIX + "/createCommunication")
    public Long createCommunication(@RequestBody CommunicationCreateDto communicationCreateDto);

    @PostMapping(COMMUNICATIONS_PREFIX + "/createCommunicationDetail")
    public Long createCommunicationDetail(@RequestBody CommunicationDetailCreateDto communicationCreateDetailDto);

    @DeleteMapping(COMMUNICATIONS_PREFIX + "/deleteCommunication")
    public Boolean deleteCommunication(@RequestParam(value = "userId", required = true) Long userId,
                                       @RequestParam(value = "communicationId", required = true) Long communicationId);

    @PostMapping(COMMUNICATIONS_PREFIX + "/updateCommunicationReadFlag")
    public Boolean updateCommunicationReadFlag(
            @RequestParam(value = "communicationId", required = true) Long communicationId,
            @RequestParam(value = "communicationDetailId", required = true) Long communicationDetailId,
            @RequestParam(value = "readUserId", required = true) Long readUserId);

    @PostMapping(COMMUNICATIONS_PREFIX + "/unread/count")
    CommunicationUnreadCount getUnreadCount(@RequestParam(value = "readUserId", required = true) Long readUserId,
                                            @RequestParam(value = "userType", required = true) String userType);

    /**
     * 获取parentId下的部门列表
     *
     * @param parentId
     * @return
     */
    @GetMapping(DEPT_PREFIX + "/list")
    @Override
    List<DeptVo> listDeptByParentId(@RequestParam(value = "parentId", required = true) Long parentId);

    /**
     * 获取今日推荐列表
     *
     * @param userId     用户id
     * @param hospitalId 医院id
     * @param pageNo     页码
     * @param pageSize   条数
     * @return
     */
    @GetMapping(SYS_PREFIX + "/app/recommendList")
    List<AppRecommend> getAppRecommends(
            @RequestParam(value = "userId", required = true) Long userId,
            @RequestParam(value = "hospitalId", required = false) Long hospitalId,
            @RequestParam(value = "pageNo", required = true) Long pageNo,
            @RequestParam(value = "pageSize", required = true) Long pageSize
    );

    /**
     * 获取今日推荐对象
     *
     * @param recommendId 推荐id
     * @return
     */
    @GetMapping(SYS_PREFIX + "/app/recommend/detail")
    AppRecommend getAppRecommendById(@RequestParam(value = "recommendId", required = true) Long recommendId);


    /****************************************资料库**************************************************/

    /**
     * 资料库--列表
     *
     * @param userId     用户ID
     * @param hospitalId 医疗机构ID
     * @param pageNo     页数
     * @param pageSize   条数
     * @param isPage     是否分页  0 否  1 是
     * @param searchName 关键字
     * @return
     */
    @ApiOperation(value = "资料库--列表", httpMethod = "GET")
    @GetMapping(SYS_PREFIX + "/filesStorage/list")
    List<FilesStorageVo> selectFilesStorage(@RequestParam(value = "userId", required = false) Long userId,
                                            @RequestParam(value = "hospitalId", required = false) Long hospitalId,
                                            @RequestParam(value = "pageNo", required = false) Integer pageNo,
                                            @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                            @RequestParam(value = "isPage", required = true) Integer isPage,
                                            @RequestParam(value = "searchName", required = false) String searchName);

    /**
     * 资料库--详情
     *
     * @param id 资料库ID
     * @return
     */
    @ApiOperation(value = "资料库--详情", httpMethod = "GET")
    @GetMapping(SYS_PREFIX + "/filesStorage/detail")
    FilesStorageVo getFilesStorageById(@RequestParam(value = "id") Long id);

    /**
     * 资料库--添加
     *
     * @param filesStorageVo
     * @return
     */
    @ApiOperation(value = "资料库--详情", httpMethod = "POST")
    @PostMapping(SYS_PREFIX + "/filesStorage/save")
    Long insertFilesStorage(@RequestBody FilesStorageVo filesStorageVo);


    /**
     * 资料库--修改
     *
     * @param filesStorageVo
     * @return
     */
    @ApiOperation(value = "资料库--详情", httpMethod = "POST")
    @PostMapping(SYS_PREFIX + "/filesStorage/update")
    Long updateFilesStorage(@RequestBody FilesStorageVo filesStorageVo);

    /********************************医院文化制度***************************************/

    /**
     * 医院文化制度--列表
     *
     * @param type       数据字典 00015
     * @param hospitalId 医疗机构ID
     * @param pageNo     页数
     * @param pageSize   条数
     * @param isPage     是否分页  0 否  1 是
     * @param searchName 关键字
     * @return
     */
    @ApiOperation(value = "医院文化制度--列表", httpMethod = "GET")
    @GetMapping(SYS_PREFIX + "/appRegime/list")
    List<AppRegimeVo> selectAppRegime(@RequestParam(value = "type", required = true) String type,
                                      @RequestParam(value = "hospitalId", required = false) Long hospitalId,
                                      @RequestParam(value = "pageNo", required = false) Integer pageNo,
                                      @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                      @RequestParam(value = "isPage", required = true) Integer isPage,
                                      @RequestParam(value = "searchName", required = false) String searchName);

    /**
     * 医院文化制度--详情
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "医院文化制度--详情", httpMethod = "GET")
    @GetMapping(SYS_PREFIX + "/appRegime/detail")
    AppRegimeVo getAppRegimeById(@RequestParam("id") Long id);

    /**
     * 添加考勤记录
     *
     * @param punchCard 打卡对象
     * @return
     */
    @PostMapping(USER_PREFIX + "/addPunchCard")
    Integer addPunchCard(@RequestBody AppPunchCard punchCard);

    /**
     * 获取考勤记录列表
     *
     * @param userId     用户ID
     * @param hospitalId 医院ID
     * @param dateTime   考勤时间
     * @return
     */
    @GetMapping(USER_PREFIX + "/punchCardList")
    List<AppPunchCardVo> getPunchCardList(
            @RequestParam(value = "userId", required = true) Long userId,
            @RequestParam(value = "hospitalId", required = true) Long hospitalId,
            @RequestParam(value = "dateTime", required = true) Date dateTime);

    /**
     * 获取打卡记录
     *
     * @param userId     用户ID
     * @param hospitalId 医院ID
     * @param punchType  打卡类型
     * @param punchTime  打卡时间
     * @return
     */
    @GetMapping(USER_PREFIX + "/getPunchCard")
    AppPunchCardVo getPunchCard(
            @RequestParam(value = "userId", required = true) Long userId,
            @RequestParam(value = "hospitalId", required = true) Long hospitalId,
            @RequestParam(value = "punchType", required = true) String punchType,
            @RequestParam(value = "punchTime", required = true) Date punchTime);

    /**
     * 添加排班
     *
     * @param appSchedulDto 排班对象
     * @return
     */
    @PostMapping(USER_PREFIX + "/schedul/add")
    Integer addAppSchedul(@RequestBody AppSchedulDto appSchedulDto);

    /**
     * 添加排班记录
     *
     * @param appSchedulRecord 排班记录
     * @return
     */
    @PostMapping(USER_PREFIX + "/schedul/addRecord")
    Integer addAppSchedulRecord(@RequestBody AppSchedulRecord appSchedulRecord);

    /**
     * 获取排班列表
     *
     * @param userId     用户ID
     * @param hospitalId 医院ID
     * @return
     */
    @GetMapping(USER_PREFIX + "/schedul/List")
    List<AppSchedulVo> getAppSchedulList(
            @RequestParam(value = "userId", required = true) Long userId,
            @RequestParam(value = "hospitalId", required = true) Long hospitalId);

    /**
     * 获取排班记录列表
     *
     * @param userId     用户ID
     * @param hospitalId 医院ID
     * @param schedulId  排班ID
     * @return
     */
    @GetMapping(USER_PREFIX + "/schedul/recordList")
    List<AppSchedulRecordVo> getAppSchedulRecordList(
            @RequestParam(value = "userId", required = true) Long userId,
            @RequestParam(value = "hospitalId", required = true) Long hospitalId,
            @RequestParam(value = "schedulId", required = true) Long schedulId);

    /**
     * 获取微信对象
     *
     * @param appId 微信AppID
     * @return
     */
    @GetMapping(USER_PREFIX + "/app")
    WxAppVo getWxApp(@RequestParam(value = "appId", required = true) String appId);

    /**
     * 获取任务接收者当前任务
     *
     * @param receiverId 接收人用户ID
     * @return
     */
    @GetMapping(USER_PREFIX + "/getTaskByReceiverId")
    List<TaskStatusVo> getTaskByReceiverId(@RequestParam("receiverId") Long receiverId);

    /**
     * 获取分享用户列表
     *
     * @param userId 用户ID
     * @return
     */
    @PostMapping(USER_PREFIX + "/getPromoteUserList")
    List<UserVo> getPromoteUserList(@RequestParam("userId") Long userId,
                                    @RequestParam("pageNo") Long pageNo,
                                    @RequestParam("pageSize") Long pageSize);

    /**
     * 绑定分享码
     *
     * @param userId      用户ID
     * @param promoteCode 邀请码
     * @return
     */
    @PostMapping(USER_PREFIX + "/bingPromoteCode")
    Integer bingPromoteCode(@RequestParam("userId") Long userId,
                            @RequestParam("promoteCode") String promoteCode);

    /**
     * 绑定用户提现账号
     *
     * @param userId     用户ID
     * @param type       账户类型
     * @param payAccount 账号
     * @return
     */
    @PostMapping(USER_PREFIX + "/bingUserAccount")
    Integer bingUserAccount(@RequestParam(value = "userId") Long userId,
                            @RequestParam(value = "type") Integer type,
                            @RequestParam(value = "payAccount") String payAccount);

    /**
     * 编辑用户提现账号
     *
     * @param userId     用户ID
     * @param type       账户类型
     * @param payAccount 账号
     * @return
     */
    @PostMapping(USER_PREFIX + "/editUserAccount")
    Integer editUserAccount(@RequestParam(value = "userId") Long userId,
                            @RequestParam(value = "type") Integer type,
                            @RequestParam(value = "payAccount") String payAccount);

    @GetMapping(USER_PREFIX + "/getUserAccount")
    UserAccount getUserAccount(@RequestParam(value = "userId", required = true) Long userId);

    /**
     * 删除文件
     *
     * @param fileId
     * @return
     */
    @ApiOperation(value = "删除文件", httpMethod = "GET")
    @GetMapping(SYS_PREFIX + "/deleteFile")
    int deleteFile(@RequestParam("fileId") Long fileId);

    /**
     * 获取兑换规则
     *
     * @param userId
     * @return
     */
    @GetMapping(INTEGRAL_PREFIX + "/getExchangeRules")
    List<SysExchangeRules> getExchangeRules(@RequestParam(value = "userId", required = true) Long userId);

    /**
     * 积分兑换
     *
     * @param userId          用户ID
     * @param integralNum     积分数量
     * @param exchangeRulesId 规则ID
     * @return
     */
    @PostMapping(INTEGRAL_PREFIX + "/exchange")
    Integer integralExchange(@RequestParam(value = "userId", required = true) Long userId,
                             @RequestParam(value = "integralNum", required = true) Long integralNum,
                             @RequestParam(value = "exchangeRulesId", required = true) Long exchangeRulesId);

    /**
     * 获取兑换列表
     *
     * @param userId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(INTEGRAL_PREFIX + "/getExchangeRecordList")
    List<SysExchangeRecord> getExchangeRecordList(@RequestParam(value = "userId", required = true) Long userId,
                                                  @RequestParam(value = "pageNo", required = true) Long pageNo,
                                                  @RequestParam(value = "pageSize", required = true) Long pageSize
    );

    @GetMapping(COMMUNICATIONS_PREFIX + "/getcommunicationTalklist")
    List<CommunicationTalkVo> getcommunicationTalklist(@RequestParam(value = "talkUserId", required = true) Long talkUserId,
                                                       @RequestParam(value = "userId", required = true) Long userId,
                                                       @RequestParam(value = "pageNo", required = true) Long pageNo,
                                                       @RequestParam(value = "pageSize", required = true) Long pageSize);

    @PostMapping(COMMUNICATIONS_PREFIX + "/sendTalkMessage")
    Long sendTalkMessage(@RequestParam(value = "talkUserId", required = true) Long talkUserId,
                         @RequestParam(value = "userId", required = true) Long userId,
                         @RequestParam(value = "content", required = true) String content,
                         @RequestParam(value = "contentType", required = true) Integer contentType);
}
